package club.babyf.oss.autoconfigure;

import club.babyf.oss.config.OSSProperties;
import club.babyf.oss.service.aliyun.AliYunOSSProperties;
import club.babyf.oss.service.aliyun.AliYunOSSService;
import club.babyf.oss.service.local.LocalOSSProperties;
import club.babyf.oss.service.local.LocalOSSService;
import club.babyf.oss.service.OSSService;
import club.babyf.oss.service.tencent.TencentOSSProperties;
import club.babyf.oss.service.tencent.TencentOSSService;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * OSSAutoConfiguration.
 *
 * @author zhanglei.
 * @date 2024/12/31 16:10.
 * @description 对象存储自动装配.
 */
@AutoConfiguration
@EnableConfigurationProperties(OSSProperties.class)
public class OSSAutoConfiguration {

    @AutoConfiguration
    @ConditionalOnProperty(prefix = "oss", name = "provider", havingValue = "ALI_YUN")
    @EnableConfigurationProperties(AliYunOSSProperties.class)
    public static class AliYunConfig {

        @Bean
        @ConditionalOnMissingBean(OSSService.class)
        public OSSService aliYunOSSService(AliYunOSSProperties aliYunOSSProperties) {
            return new AliYunOSSService(aliYunOSSProperties);
        }

    }

    @AutoConfiguration
    @ConditionalOnProperty(prefix = "oss", name = "provider", havingValue = "TENCENT")
    @EnableConfigurationProperties(TencentOSSProperties.class)
    public static class TencentConfig {

        @Bean
        @ConditionalOnMissingBean(OSSService.class)
        public OSSService tencentOSSService(TencentOSSProperties properties) {
            return new TencentOSSService(properties);
        }

    }

    @AutoConfiguration
    @ConditionalOnProperty(prefix = "oss", name = "provider", havingValue = "LOCAL")
    @EnableConfigurationProperties(LocalOSSProperties.class)
    public static class LocalConfig {

        @Bean
        @ConditionalOnMissingBean(OSSService.class)
        public OSSService localOSSService(LocalOSSProperties localOSSProperties) {
            return new LocalOSSService(localOSSProperties);
        }

    }

}
